<template>
  <a-drawer
    :title="formInfo.id == undefined ? '新增' : '修改'"
    :maskClosable="true"
    width="65%"
    placement="right"
    :closable="true"
    @close="handleCancel"
    :destroyOnClose="true"
    :visible="visible"
    style="height: calc(100% - 55px); overflow: auto; padding-bottom: 53px"
  >
    <a-spin :spinning="confirmLoading">
      <dev-supplier-model
        ref="modalModel"
        @ok="modalEditOk"
      ></dev-supplier-model>
      <!-- <a-form-model
        ref="ruleForm"
        :model="formInfo"
        :label-col="$global.labelCol"
        :wrapper-col="$global.wrapperCol"
      >
      </a-form-model> -->
    </a-spin>
    <div class="drawer-bootom-button">
      <a-popconfirm
        title="确定放弃编辑？"
        @confirm="handleCancel"
        okText="确定"
        cancelText="取消"
      >
        <a-button style="margin-right: 0.8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading"
        >提交</a-button
      >
    </div>
  </a-drawer>
</template>

<script>
import moment from 'moment'
import { getAction, postAction } from '@/api/manage'
import devSupplierModel from './DevSupplierModel.vue'
export default {
  name: 'devSupplierEdit',
  components: {
    devSupplierModel,
  },
  data() {
    return {
      visible: false,
      confirmLoading: false,
      formInfo: {
        companyName: undefined,
        createTime: undefined,
        legalPerson: undefined,
        unifiedCode: undefined,
        registrationNo: undefined,
        incorporationDate: undefined,
        bankAccount: undefined,
        backAccountName: undefined,
        fixedTelephone: undefined,
        email: undefined,
        remarks: undefined,
        economize: undefined,
        market: undefined,
        distinguish: undefined,
        address: undefined,
        website: undefined,
        profile: undefined,
        category: undefined,
        brand: undefined,
        legalPersonType: undefined,
        legalPersonIdImage1: undefined,
        legalPersonIdImage2: undefined,
        legalPersonIdNumber: undefined,
        legalPersonIsLongTerm: undefined,
        startNumberPeriodValidityDate: undefined,
        endNumberPeriodValidityDate: undefined,
        businessLicenseImage: undefined,
        businessIsLongTerm: undefined,
        startBusinessPeriodValidityDate: undefined,
        endBusinessPeriodValidityDate: undefined,
        companyLogo: undefined,
        collaborativeKey: undefined,
        checkCode: undefined,
        wx: '',
      },
      // drawerWidth: 90%,
      url: {
        saveInfo: '/system/devSupplier/save',
        getInfo: '/system/devSupplier/info',
      },
    }
  },
  created() {},
  methods: {
    add() {
      this.edit()
    },
    moment,
    // 保存报错信息提示
    modalEditOk(val) {
      if (val.code == '0000') {
        //数据提交成功
        this.$message.success('提交成功')
        this.$emit('ok', val)
        this.close()
        console.log('数据提交成功')
      } else {
        //数据提交失败
        if (val.msg != '') {
          this.$message.error(val.msg)
        }
        this.confirmLoading = false
        console.log('数据提交失败')
      }
    },
    edit(record) {
      this.$objToOverride(this.formInfo, record)
      if (this.formInfo.id) {
        getAction(this.url.getInfo, { id: record.id }).then((res) => {
          this.$nextTick(() => {
            this.$refs.modalModel.getCollabora(res.result.data, '0')
          })
        })
      }
      this.visible = true
    },
    // 确定
    handleSubmit() {
      // 触发表单验证
      this.confirmLoading = true
      this.$refs.modalModel.handleSubmit()
    },
    // 关闭
    handleCancel() {
      this.close()
    },
    close() {
      // this.$refs.ruleForm.closeModel()
      this.$objToReset(this.formInfo)
      this.$emit('close')
      this.$refs.modalModel.closeModel()
      this.visible = false
    },
    editorOk(val) {
      console.log('val>', val)
      this.close()
    },
  },
}
</script>
